package pers.bbw.crr.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pers.bbw.crr.dto.SiteSearchDto;
import pers.bbw.crr.entity.Site;
import pers.bbw.crr.service.SiteService;
import pers.bbw.crr.util.AjaxResult;

import javax.annotation.Resource;

/**
 * 场地信息控制器
 *
 * @author bbw
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/site")
@Api(tags = "场地信息控制器")
public class SiteController {

    @Resource
    private SiteService siteService;

    /**
     * 查询场地列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "分页查询", notes = "白博文 0205")
    public AjaxResult list(@ApiParam(value = "场地信息") SiteSearchDto dto) {
        return AjaxResult.success(siteService.selectSiteList(dto));
    }

    /**
     * 获取场地详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情", notes = "白博文 0205")
    public AjaxResult getInfo(@ApiParam(value = "场地信息id") @PathVariable("id") int id) {
        return AjaxResult.success(siteService.selectSiteById(id));
    }

    /**
     * 新增场地
     */
    @PostMapping
    @ApiOperation(value = "新增", notes = "白博文 0205")
    public AjaxResult add(@ApiParam(value = "场地信息") @RequestBody Site site, MultipartFile file) {
        siteService.insertSite(site, file);
        return AjaxResult.success();
    }

    /**
     * 修改场地
     */
    @PutMapping
    @ApiOperation(value = "修改", notes = "白博文 0205")
    public AjaxResult edit(@ApiParam(value = "场地信息") @RequestBody Site site, MultipartFile file) {
        siteService.updateSite(site, file);
        return AjaxResult.success();
    }

    /**
     * 删除场地
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "批量删除", notes = "白博文 0205")
    public AjaxResult remove(@ApiParam(value = "用户id数组") @PathVariable int[] ids) {
        return AjaxResult.success(siteService.deleteSiteByIds(ids));
    }

}
